#include "WardPerceptualReproduction.h"

WardPerceptualReproduction::WardPerceptualReproduction(double _Ldmax, double _Lwmax, double Lwa): ToneReproductionModel(_Ldmax, _Lwmax){
	Lw = Lwa;
}

void WardPerceptualReproduction::calculateLd(){
	Ld = pow(((1.219+pow((Ldmax/2),0.4)) / (1.219+pow(Lw,0.4))), 2.5);
}

void WardPerceptualReproduction::adjustScene(vector<MyColor>* pixels){
	if(Lw == 0){
		calculateLw(pixels);
	}
	calculateLd();

	for(size_t i = 0; i < pixels->size(); i++){
		MyColor* iColor = &(pixels->at(i));
		if(iColor->r < 0){
			iColor->r = 0;
		}
		else if(iColor->r > 1){
			iColor->r = 1;
		}
		if(iColor->g < 0){
			iColor->g = 0;
		}
		else if(iColor->g > 1){
			iColor->g = 1;
		}
		if(iColor->b < 0){
			iColor->b = 0;
		}
		else if(iColor->b > 1){
			iColor->b = 1;
		}
     
		iColor->r *= Ld;
		iColor->g *= Ld;
		iColor->b *= Ld;
	}

	Lw = 0;
}